package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursing_project")
@Api(tags = "护理模块相应接口")
public class NursingProjectController {
    @Autowired
    private NursingProjectService nursingProjectService;

    @GetMapping
    @ApiOperation("护理分页接口")
    public ResponseResult<PageResponse<NursingProjectVo>> pageNursing(@ApiParam("护理项目名称") @RequestParam(value = "name", required = false) String name,
                                                                      @ApiParam("当前页码") @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                                      @ApiParam("每页显示条数") @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                                      @ApiParam("状态（0：禁用，1：启用）") @RequestParam(value = "status", required = false) Integer status) {
        PageResponse<NursingProjectVo> pageResponse = nursingProjectService.pageNursing(name, pageNum, pageSize, status);
        return ResponseResult.success(pageResponse);
    }

    @ApiOperation("新增")
    @PostMapping()
    public ResponseResult addNursingData(@RequestBody NursingProjectDto nursingProjectDto) {
        nursingProjectService.addNursingData(nursingProjectDto);
        return ResponseResult.success();
    }

    @ApiOperation("根据id查询护理")
    @GetMapping("/{id}")
    public ResponseResult<NursingProjectVo> getNursingById(@PathVariable(value = "id") Long id) {
        NursingProjectVo nursingProjectVo = nursingProjectService.getNursingProject(id);
        return ResponseResult.success(nursingProjectVo);
    }

    @ApiOperation("编辑")
    @PutMapping
    public ResponseResult updateNursingProject(@RequestBody NursingProjectDto nursingProjectDto) {
        nursingProjectService.updateNursingProject(nursingProjectDto);
        return ResponseResult.success();
    }

    @ApiOperation("删除")
    @DeleteMapping("/{id}")
    public ResponseResult deleteNursingProject(@PathVariable(value = "id") Long id) {
        nursingProjectService.deleteNursingProject(id);
        return ResponseResult.success();
    }

    @ApiOperation("启用禁用")
    @PutMapping("/{id}/status/{status}")
    public ResponseResult enableOrForbidden(@PathVariable(value = "id") Long id,
                                            @PathVariable(value = "status") Integer status) {
        nursingProjectService.enableOrForbidden(id, status);
        return ResponseResult.success();
    }

    @ApiOperation("查询所有护理项目")
    @GetMapping("/all")
    public ResponseResult<List<NursingProjectVo>> getAllNursingProject() {
        List<NursingProjectVo> nursingProjectVoList = nursingProjectService.getAllNursingProject();
        return ResponseResult.success(nursingProjectVoList);
    }
}
